package com.ohs.bo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.ohs.bll.util.ConfigurationManager;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class CommonInterceptor implements Interceptor {
	public static final String PROD_URL = "productUrl";

	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext context = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest) context
				.get(ServletActionContext.HTTP_REQUEST);

		HttpSession session = request.getSession(true);

		Object url = session.getAttribute(PROD_URL);
		if (url == null) {
			url = ConfigurationManager.getAsString(ConfigurationManager.CONFIG, "product.url");
			session.setAttribute(PROD_URL, url);
		}
		return invocation.invoke();
	}

	public void destroy() {
		// TODO Auto-generated method stub

	}

	public void init() {
		// TODO Auto-generated method stub

	}

}
